from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-08-15 14:03:47.278215
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 15, Aug, 2022
Time: 14:03:53
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.1446
Nobs: 749.000 HQIC: -50.4857
Log likelihood: 9511.92 FPE: 9.58236e-23
AIC: -50.6995 Det(Omega_mle): 8.50419e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.293942 0.055289 5.316 0.000
L1.Burgenland 0.108397 0.036695 2.954 0.003
L1.Kärnten -0.106914 0.019456 -5.495 0.000
L1.Niederösterreich 0.206996 0.076510 2.705 0.007
L1.Oberösterreich 0.110129 0.074774 1.473 0.141
L1.Salzburg 0.254407 0.039208 6.489 0.000
L1.Steiermark 0.040194 0.051166 0.786 0.432
L1.Tirol 0.108322 0.041520 2.609 0.009
L1.Vorarlberg -0.061748 0.035613 -1.734 0.083
L1.Wien 0.050973 0.066124 0.771 0.441
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.061172 0.115414 0.530 0.596
L1.Burgenland -0.033934 0.076599 -0.443 0.658
L1.Kärnten 0.047375 0.040614 1.166 0.243
L1.Niederösterreich -0.174927 0.159711 -1.095 0.273
L1.Oberösterreich 0.407232 0.156088 2.609 0.009
L1.Salzburg 0.287454 0.081846 3.512 0.000
L1.Steiermark 0.107751 0.106808 1.009 0.313
L1.Tirol 0.311632 0.086672 3.596 0.000
L1.Vorarlberg 0.024888 0.074341 0.335 0.738
L1.Wien -0.030933 0.138031 -0.224 0.823
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.188406 0.028373 6.640 0.000
L1.Burgenland 0.089669 0.018831 4.762 0.000
L1.Kärnten -0.008699 0.009984 -0.871 0.384
L1.Niederösterreich 0.259855 0.039263 6.618 0.000
L1.Oberösterreich 0.138453 0.038372 3.608 0.000
L1.Salzburg 0.045208 0.020121 2.247 0.025
L1.Steiermark 0.020194 0.026257 0.769 0.442
L1.Tirol 0.093208 0.021307 4.374 0.000
L1.Vorarlberg 0.056868 0.018276 3.112 0.002
L1.Wien 0.118003 0.033933 3.478 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.107399 0.028835 3.725 0.000
L1.Burgenland 0.045579 0.019137 2.382 0.017
L1.Kärnten -0.013810 0.010147 -1.361 0.174
L1.Niederösterreich 0.189331 0.039902 4.745 0.000
L1.Oberösterreich 0.301551 0.038997 7.733 0.000
L1.Salzburg 0.109732 0.020449 5.366 0.000
L1.Steiermark 0.103204 0.026685 3.867 0.000
L1.Tirol 0.105737 0.021654 4.883 0.000
L1.Vorarlberg 0.069315 0.018573 3.732 0.000
L1.Wien -0.018894 0.034486 -0.548 0.584
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.126509 0.052485 2.410 0.016
L1.Burgenland -0.050107 0.034834 -1.438 0.150
L1.Kärnten -0.040789 0.018469 -2.208 0.027
L1.Niederösterreich 0.172117 0.072630 2.370 0.018
L1.Oberösterreich 0.138488 0.070982 1.951 0.051
L1.Salzburg 0.288976 0.037220 7.764 0.000
L1.Steiermark 0.035407 0.048572 0.729 0.466
L1.Tirol 0.163711 0.039415 4.154 0.000
L1.Vorarlberg 0.099553 0.033807 2.945 0.003
L1.Wien 0.068150 0.062770 1.086 0.278
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.056482 0.041748 1.353 0.176
L1.Burgenland 0.039405 0.027708 1.422 0.155
L1.Kärnten 0.051032 0.014691 3.474 0.001
L1.Niederösterreich 0.218451 0.057772 3.781 0.000
L1.Oberösterreich 0.294690 0.056461 5.219 0.000
L1.Salzburg 0.043802 0.029606 1.479 0.139
L1.Steiermark -0.000422 0.038635 -0.011 0.991
L1.Tirol 0.144168 0.031352 4.598 0.000
L1.Vorarlberg 0.071912 0.026891 2.674 0.007
L1.Wien 0.081289 0.049930 1.628 0.104
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.174388 0.049849 3.498 0.000
L1.Burgenland -0.002617 0.033084 -0.079 0.937
L1.Kärnten -0.062522 0.017542 -3.564 0.000
L1.Niederösterreich -0.077880 0.068982 -1.129 0.259
L1.Oberösterreich 0.188961 0.067417 2.803 0.005
L1.Salzburg 0.058293 0.035351 1.649 0.099
L1.Steiermark 0.234464 0.046132 5.082 0.000
L1.Tirol 0.498911 0.037435 13.327 0.000
L1.Vorarlberg 0.044886 0.032109 1.398 0.162
L1.Wien -0.054560 0.059618 -0.915 0.360
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.160665 0.057626 2.788 0.005
L1.Burgenland -0.008946 0.038246 -0.234 0.815
L1.Kärnten 0.066591 0.020278 3.284 0.001
L1.Niederösterreich 0.206960 0.079744 2.595 0.009
L1.Oberösterreich -0.070005 0.077934 -0.898 0.369
L1.Salzburg 0.210750 0.040866 5.157 0.000
L1.Steiermark 0.120224 0.053329 2.254 0.024
L1.Tirol 0.072585 0.043275 1.677 0.093
L1.Vorarlberg 0.119452 0.037118 3.218 0.001
L1.Wien 0.123143 0.068919 1.787 0.074
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.358653 0.033055 10.850 0.000
L1.Burgenland 0.007033 0.021938 0.321 0.749
L1.Kärnten -0.023499 0.011632 -2.020 0.043
L1.Niederösterreich 0.213580 0.045742 4.669 0.000
L1.Oberösterreich 0.199321 0.044704 4.459 0.000
L1.Salzburg 0.044326 0.023441 1.891 0.059
L1.Steiermark -0.013824 0.030590 -0.452 0.651
L1.Tirol 0.104564 0.024823 4.212 0.000
L1.Vorarlberg 0.071605 0.021292 3.363 0.001
L1.Wien 0.040117 0.039533 1.015 0.310
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.038685 0.140168 0.192724 0.151359 0.119022 0.103153 0.064227 0.217652
Kärnten 0.038685 1.000000 -0.007275 0.131910 0.039231 0.093739 0.432779 -0.053629 0.097020
Niederösterreich 0.140168 -0.007275 1.000000 0.334551 0.141275 0.292914 0.096395 0.179980 0.313327
Oberösterreich 0.192724 0.131910 0.334551 1.000000 0.228360 0.326202 0.176408 0.167392 0.261853
Salzburg 0.151359 0.039231 0.141275 0.228360 1.000000 0.143322 0.112774 0.145310 0.123785
Steiermark 0.119022 0.093739 0.292914 0.326202 0.143322 1.000000 0.146726 0.137580 0.071529
Tirol 0.103153 0.432779 0.096395 0.176408 0.112774 0.146726 1.000000 0.112642 0.142904
Vorarlberg 0.064227 -0.053629 0.179980 0.167392 0.145310 0.137580 0.112642 1.000000 0.002270
Wien 0.217652 0.097020 0.313327 0.261853 0.123785 0.071529 0.142904 0.002270 1.000000